<template>
	<view>

		<view class="box">
			<view class="list">
				<view class="list-item" v-for="it in list" @click="toDetail(it)">
					<view class="list-item-l">
						<view class="list-item-l-title">{{it.title}}</view>
						<view class="list-item-l-time">{{it.add_time}}</view>
					</view>
					<view class="list-item-remark">{{it.content}}</view>
					<view class="point" v-if="item.type!=6&&it.status==0"></view>
				</view>
			</view>
		</view>

	</view>

</template>

<script>
	import {
		message_list,mark_all_read,
		message_details
	} from '@/common/http/api.js'
	export default {
		data() {
			return {
				//分页
				params: {
					page: 1
				},
				isList: true,
				list: [],
			};
		},
		onShow(e) {
			mark_all_read().then(res=>{
				this.reload()
			})
			
			
		},
		onReachBottom(){
			 this.params.page++
			 this.init()
		},
		methods: {
			reload() {
				this.list = []
				this.params.page = 1
				this.init()
			},
			toDetail(e) {
				if(e.type!=1&&e.parameter==0){
					message_details({
						id: e.id
					})
					return
				}				
				
				if (e.type == 1) { //公告
					uni.navigateTo({
						url: "/pagesC/message/detail?id=" + e.id
					})
				} else if (e.type == 2) { //日志
					uni.navigateTo({
						url: "/pages/circle/detail?id=" + e.parameter
					})
					message_details({
						id: e.id
					})

				} else if (e.type == 3) { //商品
					uni.navigateTo({
						url: "/pagesA/shopping/detail?id=" + e.parameter+'&type=3'
					})
					message_details({
						id: e.id
					})

				} else if (e.type == 4) { //视频
					uni.navigateTo({
						url: "/pagesB/teachingCourses/teachingCourses?id=" + e.parameter
					})
					message_details({
						id: e.id
					})


				} else if (e.type == 5) { //名片
					uni.navigateTo({
						url: "/pages/index/other?shareId=" + e.parameter
					})

					message_details({
						id: e.id
					})
				} else if (e.type == 6) { //名片
					uni.navigateTo({
						url: "/pagesA/aboutUs/aboutUs?id=" + e.parameter
					})

					message_details({
						id: e.id
					})
				}

			},
			init() {

				message_list(this.params).then(res => {

					if (Array.isArray(res.data.list) && res.data.list.length > 0) {
						if (this.params.page === 1) {
							this.list = res.data.list
						} else {
							this.list = this.list.concat(res.data.list)
						}


					} else {
						this.isList = false
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #F6F7F8;
	}

	.list {
		width: 100%;
		overflow: hidden;

		.list-item {
			margin-top: 30rpx;
			width: 690rpx;
			box-sizing: border-box;
			padding: 26rpx 28rpx;

			background: white;
			margin-left: 30rpx;
			background: #fff;
			border-radius: 20rpx;
			position: relative;

			.point {
				position: absolute;
				width: 12rpx;
				height: 12rpx;
				border-radius: 50%;
				right: 8rpx;
				top: 8rpx;
				background: #f56c6c;
			}


			.list-item-l {
				display: flex;
				// align-items: center;
				justify-content: space-between;
				margin-bottom: 33rpx;

				.list-item-l-title {
					font-family: PingFang SC;
					font-weight: 400;
					font-size: 30rpx;
					color: #131313;
					margin-left: 10rpx;
					flex: 1;

				}



				.list-item-l-time {
					margin-left: 10rpx;
					font-family: PingFang SC;
					font-weight: 300;
					font-size: 24rpx;
					color: #999999;
					white-space: nowrap;
					width: 220rpx;
				}
			}

			.list-item-remark {
				font-family: PingFang SC;
				font-size: 28rpx;
				color: #999999;
				font-weight: 200;
				// overflow: hidden;
				// white-space: nowrap;
				// text-overflow: ellipsis;
			}

			.list-item-r {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 36rpx;
				color: green;
			}
		}
	}

	.success {
		color: green;
	}

	.warning {
		color: orange;
	}

	.error {
		color: red;
	}
</style>